subroutine imageconvolution( A,m,n, F,F_rows,F_cols, C  )
    implicit none
    integer, parameter :: dp = kind(0.e0)    
    real(dp),dimension(m,n) :: A,C
    real(dp),dimension(-F_rows/2:F_rows/2,-F_cols/2:F_cols/2) :: F
    integer :: m,n,F_rows,F_cols, i,j,r,s
    integer :: lrow,urow,lcol,ucol


    r=F_rows/2
    s=F_cols/2
    C= A*0.0
    do i=-r,r 
       lrow = max(1,1-i)
       urow = min(m,m-i)
       do j = -s,s
           lcol = max(1,1-j)
           ucol = min(n,n-j)
           C(lrow:urow,lcol:ucol) = C(lrow:urow,lcol:ucol) + F(-i,-j) * A(lrow+i:urow+i,lcol+j:ucol+j)
      enddo
   enddo





	!# Size of the image
	![m,n] = A.shape
!	
	!# Offsets to center of the filter
	!r = F.shape[0]/2
	!s = F.shape[1]/2
	
	!# Clear by assigning the image scaled with the center value of the filter
	!C = F[0+r,0+s]*A
	
	!# Non-center filter values
	!for i in range(-r,r+1):
!		# Bounds for indexing the rows: [lrow,urow) and [lrow+i,urow+i) in [0,m)
		!lrow = max(0,0-i)
		!urow = min(m,m-i) # ensure 
		!for j in range(-s,s+1):
			!if i!=0 or j!=0:
				!# Bounds for indexing the cols: [lrow,urow) and [lcol+j,ucol+j) in [0,m)
				!lcol = max(0,0-j)
				!ucol = min(n,n-j)
				!C[lrow:urow,lcol:ucol] += F[-i+r,-j+s]*A[(lrow+i):(urow+i),(lcol+j):(ucol+j)]
	
	!return C
    
    
end subroutine imageconvolution
